function [vl_lwin2_lwon1,vh_lwin2_lwon1,vl_llose2_lwon1,vh_llose2_lwon1,vl_lwin2_llost1,vh_lwin2_llost1,vl_llose2_llost1,vh_llose2_llost1,p_lwin2_lwon1,p_llose2_lwon1,p_lwin2_llost1,p_llose2_llost1]=transition_prob_stage2(parameter,tpORtp3h,Cpm25,parameter_fixed,c_l,c_h,V_l,V_h)


N=size(c_l,1);

% Parameters that are fixed
cutoff_tp =parameter_fixed(1);
cutoff_pm =parameter_fixed(2);
delta_0   =parameter_fixed(3);
cutoff2_tp=parameter_fixed(4);    % Two bins for each environmental condition
cutoff2_pm=parameter_fixed(5);

% Parameters that are estimated
k        =parameter(1);
delta_tp =parameter(3);
delta_pm =parameter(4);
delta2_tp=parameter(5);           % Two bins for each environmental condition
delta2_pm=parameter(6);

% Two bins for each environmental condition
delta = repmat(delta_0,N,1) + delta_tp*(tpORtp3h>cutoff_tp).*(tpORtp3h<=cutoff2_tp) + delta2_tp*(tpORtp3h>cutoff2_tp)...
                            + delta_pm*(Cpm25>cutoff_pm).*(Cpm25<=cutoff2_pm)       + delta2_pm*(Cpm25>cutoff2_pm);


% Call on transition_prob_oneshot
[p_lwin3,p_llose3]=transition_prob_oneshot(c_l,c_h,V_l,V_h,k);

% Equilibrium effort costs incurred in stage 3: Equal across symmetric players (equal marginal cost and equal contest prizes) 
effortcostl_stage3=k*V_l.*( ((c_l./c_h).*(V_h./V_l)).^k ) ./ ( (ones(N,1)+((c_l./c_h).*(V_h./V_l)).^k).^2 );
effortcosth_stage3=k*V_h.*( ((c_h./c_l).*(V_l./V_h)).^k ) ./ ( (ones(N,1)+((c_h./c_l).*(V_l./V_h)).^k).^2 );

% Conditional on lwon1: Continuation values (in stage 3) conditional on stage-2 outcome (and stage-1 history)
vl_lwin2_lwon1 =V_l;                                        % For the two-setter here, player l earns the player-specific contest prize in stage 2 (no stage-3 utility flow)
vh_lwin2_lwon1 =zeros(N,1);
vl_llose2_lwon1=p_lwin3 .*V_l - effortcostl_stage3 - delta; % Each player's respective contest prize may be earned & effort cost & per-battle environmental disutility to be incurred in stage 3
vh_llose2_lwon1=p_llose3.*V_h - effortcosth_stage3 - delta;
spread_l=vl_lwin2_lwon1-vl_llose2_lwon1;                    % Player l's stage-2 win/lose payoff spread, conditional on lwon1
spread_h=vh_llose2_lwon1-vh_lwin2_lwon1;                    % Player h's stage-2 win/lose payoff spread, conditional on lwon1
% Equilibrium effort costs incurred in stage 2: Different across players given different win/lose payoffs spreads in stage 2
effortcostl_stage2=k*spread_l.*( ((c_l./c_h).*(spread_h./spread_l)).^k ) ./ ( (ones(N,1)+((c_l./c_h).*(spread_h./spread_l)).^k).^2 );
effortcosth_stage2=k*spread_h.*( ((c_h./c_l).*(spread_l./spread_h)).^k ) ./ ( (ones(N,1)+((c_h./c_l).*(spread_l./spread_h)).^k).^2 );
    % CORNER: If vh_llose2_lwon1<=0 <=> spread_h<=0, then battle-1 loser (player h in this case) throws the towel in battle 2: it is best to not exert effort, finish 2-0 and secure CV=0, than to try to transition to 1-1 with CV<0
    effortcostl_stage2=effortcostl_stage2.*(vh_llose2_lwon1>0);
    effortcosth_stage2=effortcosth_stage2.*(vh_llose2_lwon1>0);
    zero_spread_h=(spread_h==0);                 % Need to handle division by spread_h=0, which returned NaN
    effortcosth_stage2(zero_spread_h)=0;
% Divide a player's equilibrium effort cost by marginal cost to obtain effort choice; lambda=1
xl2_lwon1=effortcostl_stage2./c_l;
xh2_lwon1=effortcosth_stage2./c_h;
% Transition probabilities   
p_lwin2_lwon1 = xl2_lwon1.^k ./ (xl2_lwon1.^k + xh2_lwon1.^k);
% Can subsequently call on transition_prob_oneshot to speed up; as well as comment out the clear command?
%p_lwin2_lwon1=ones(N,1)./(ones(N,1)+(c_l./c_h.*spread_h./spread_l).^k);
%p_lwin2_lwon1=transition_prob_oneshot(c_l,c_h,spread_l,spread_h,k);
    % CORNER
    p_lwin2_lwon1(xl2_lwon1==0)=1;              % In battle 2, player l exerts infinitesimally positive effort and wins over player h who exerts 0 effort
p_llose2_lwon1=ones(N,1)-p_lwin2_lwon1;
clear spread_l spread_h effortcostl_stage2 effortcosth_stage2 zero_spread_h;
clear effortcost_stage3;

% Conditional on llost1: Continuation values (in stage 3) conditional on stage-2 outcome (and stage-1 history)
vl_lwin2_llost1 =vl_llose2_lwon1;                           
vh_lwin2_llost1 =vh_llose2_lwon1;			
vl_llose2_llost1=zeros(N,1);	
vh_llose2_llost1=V_h;                                       % For the two-setter here, player h earns the player-specific contest prize in stage 2 (no stage-3 utility flow)
spread_l=vl_lwin2_llost1-vl_llose2_llost1;                  % Player l's stage-2 win/lose payoff spread, conditional on llost1
spread_h=vh_llose2_llost1-vh_lwin2_llost1;                  % Player h's stage-2 win/lose payoff spread, conditional on llost1
% Equilibrium effort costs incurred in stage 2: Different across players given different win/lose payoffs spreads in stage 2
effortcostl_stage2=k*spread_l.*( ((c_l./c_h).*(spread_h./spread_l)).^k ) ./ ( (ones(N,1)+((c_l./c_h).*(spread_h./spread_l)).^k).^2 );
effortcosth_stage2=k*spread_h.*( ((c_h./c_l).*(spread_l./spread_h)).^k ) ./ ( (ones(N,1)+((c_h./c_l).*(spread_l./spread_h)).^k).^2 );
    % CORNER: If vl_lwin2_llost1<=0 <=> spread_l<=0, then battle-1 loser (player l in this case) throws the towel in battle 2: it is best to not exert effort, finish 0-2 and secure CV=0, than to try to transition to 1-1 with CV<0
    effortcostl_stage2=effortcostl_stage2.*(vl_lwin2_llost1>0);
    effortcosth_stage2=effortcosth_stage2.*(vl_lwin2_llost1>0);
    zero_spread_l=(spread_l==0);                 % Need to handle division by spread_l=0, which returned NaN 
    effortcostl_stage2(zero_spread_l)=0;
% Divide a player's equilibrium effort cost by marginal cost to obtain effort choice; lambda=1
xl2_llost1=effortcostl_stage2./c_l;
xh2_llost1=effortcosth_stage2./c_h;
% Transition probabilities
p_lwin2_llost1 = xl2_llost1.^k ./ (xl2_llost1.^k + xh2_llost1.^k);
% Can subsequently call on transition_prob_oneshot to speed up; as well as comment out the clear commands?
%p_lwin2_llost1=ones(N,1)./(ones(N,1)+(c_l./c_h.*spread_h./spread_l).^k);
%p_lwin2_llost1=transition_prob_oneshot(c_l,c_h,spread_l,spread_h,k);
    % CORNER
    p_lwin2_llost1(xl2_llost1==0)=0;              % In battle 2, player h exerts infinitesimally positive effort and wins over player l who exerts 0 effort
p_llose2_llost1=ones(N,1)-p_lwin2_llost1;
clear spread_l spread_h effortcostl_stage2 effortcosth_stage2 zero_spread_l;

end